import {defineStore} from "pinia";
import {reactive, ref} from "vue";
import {io, Socket} from "socket.io-client";

export const useIndexStore = defineStore(
    "Index",
    () => {
        // 默认后端基址
        const baseURL = "http://localhost:3000";
        // 用于存放全局socket实例
        let socket;
        // 是否是移动端
        const isMobile = ref(false);
        // 是否为搜索页
        const search_page = ref(false);
        // 是否为暗色模式
        const is_dark = ref(false);
        // 发送方式
        const send_way = ref("enter");
        // 关闭搜索页
        const close_search = () => {
            search_page.value = false;
        };
        // 初始化socket
        const init_socket = (options: object) => {
            socket = io(baseURL, options)
        }
        const get_socket = () => {
            return socket;
        }
        const video_item = reactive({})
        const video_list = reactive([])
        return {
            isMobile,
            search_page,
            close_search,
            init_socket,
            is_dark,
            socket,
            baseURL,
            send_way,
            get_socket,
            video_item,
            video_list,
        };
    },
);
